import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/home',
    component: Layout,
    redirect: '/home/index',
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' },
      hidden: true
    }]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/menuManage',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'menuManage',
        name: '菜单管理',
        component: () => import('@/views/system/MenuManage.vue'),
        meta: { title: '菜单管理' }
      },
      {
        path: 'department',
        name: '部门管理',
        component: () => import('@/views/system/DepartmentManage.vue'),
        meta: { title: '部门管理' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
